<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.6"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>AngelScript: grid template object</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
  $(document).ready(function() { init_search(); });
/* @license-end */
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr id="projectrow">
  <td id="projectlogo"><img alt="Logo" src="aslogo_small.png"/></td>
  <td id="projectalign">
   <div id="projectname">AngelScript
   </div>
  </td>
    <td>        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <span id="MSearchSelect"                onmouseover="return searchBox.OnSearchSelectShow()"                onmouseout="return searchBox.OnSearchSelectHide()">&#160;</span>
          <input type="text" id="MSearchField" value="" placeholder="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.svg" alt=""/></a>
          </span>
        </div>
</td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.6 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search/",'.html');
/* @license-end */
</script>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(document).ready(function(){initNavTree('doc_addon_grid.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">Loading...</div>
<div class="SRStatus" id="Searching">Searching...</div>
<div class="SRStatus" id="NoMatches">No Matches</div>
</div>
</div>
</div>
</div>

<div><div class="header">
  <div class="headertitle"><div class="title">grid template object </div></div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p><b>Path:</b> /sdk/add_on/scriptgrid/</p>
<p>The <code>grid</code> type is a <a class="el" href="doc_adv_template.html">template object</a> that allow the scripts to declare 2D grids of any type. In many ways it is similar to the <a class="el" href="doc_addon_array.html">array template object</a>, but it is specialized for use with areas.</p>
<p>The type is registered with <code>RegisterScriptGrid(asIScriptEngine *engine)</code>.</p>
<h1><a class="anchor" id="doc_addon_grid_1"></a>
Public C++ interface</h1>
<div class="fragment"><div class="line"><span class="keyword">class </span>CScriptGrid</div>
<div class="line">{</div>
<div class="line"><span class="keyword">public</span>:</div>
<div class="line">  <span class="comment">// Set the memory functions that should be used by all CScriptGrids</span></div>
<div class="line">  <span class="keyword">static</span> <span class="keywordtype">void</span> SetMemoryFunctions(<a class="code hl_typedef" href="angelscript_8h.html#abfe11f5787462216b1682a5d3f5486be">asALLOCFUNC_t</a> allocFunc, <a class="code hl_typedef" href="angelscript_8h.html#adeecc934971e695fc4441a47694860fb">asFREEFUNC_t</a> freeFunc);</div>
<div class="line"> </div>
<div class="line">  <span class="comment">// Factory functions</span></div>
<div class="line">  <span class="keyword">static</span> CScriptGrid *Create(<a class="code hl_class" href="classas_i_type_info.html">asITypeInfo</a> *gridType);</div>
<div class="line">  <span class="keyword">static</span> CScriptGrid *Create(<a class="code hl_class" href="classas_i_type_info.html">asITypeInfo</a> *gridType, <a class="code hl_typedef" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> width, <a class="code hl_typedef" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> height);</div>
<div class="line">  <span class="keyword">static</span> CScriptGrid *Create(<a class="code hl_class" href="classas_i_type_info.html">asITypeInfo</a> *gridType, <a class="code hl_typedef" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> width, <a class="code hl_typedef" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> height, <span class="keywordtype">void</span> *defaultValue);</div>
<div class="line">  <span class="keyword">static</span> CScriptGrid *Create(<a class="code hl_class" href="classas_i_type_info.html">asITypeInfo</a> *gridType, <span class="keywordtype">void</span> *listBuffer);</div>
<div class="line"> </div>
<div class="line">  <span class="comment">// Memory management</span></div>
<div class="line">  <span class="keywordtype">void</span> AddRef() <span class="keyword">const</span>;</div>
<div class="line">  <span class="keywordtype">void</span> Release() <span class="keyword">const</span>;</div>
<div class="line"> </div>
<div class="line">  <span class="comment">// Type information</span></div>
<div class="line">  <a class="code hl_class" href="classas_i_type_info.html">asITypeInfo</a>   *GetGridObjectType() <span class="keyword">const</span>;</div>
<div class="line">  <span class="keywordtype">int</span>            GetGridTypeId() <span class="keyword">const</span>;</div>
<div class="line">  <span class="keywordtype">int</span>            GetElementTypeId() <span class="keyword">const</span>;</div>
<div class="line"> </div>
<div class="line">  <span class="comment">// Size</span></div>
<div class="line">  <a class="code hl_typedef" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> GetWidth() <span class="keyword">const</span>;</div>
<div class="line">  <a class="code hl_typedef" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> GetHeight() <span class="keyword">const</span>;</div>
<div class="line">  <span class="keywordtype">void</span>   Resize(<a class="code hl_typedef" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> width, <a class="code hl_typedef" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> height);</div>
<div class="line">  </div>
<div class="line">  <span class="comment">// Get a pointer to an element. Returns 0 if out of bounds</span></div>
<div class="line">  <span class="keywordtype">void</span>       *At(<a class="code hl_typedef" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> x, <a class="code hl_typedef" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> y);</div>
<div class="line">  <span class="keyword">const</span> <span class="keywordtype">void</span> *At(<a class="code hl_typedef" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> x, <a class="code hl_typedef" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> y) <span class="keyword">const</span>;</div>
<div class="line"> </div>
<div class="line">  <span class="comment">// Set value of an element. </span></div>
<div class="line">  <span class="comment">// The value arg should be a pointer to the value that will be copied to the element.</span></div>
<div class="line">  <span class="comment">// Remember, if the grid holds handles the value parameter should be the </span></div>
<div class="line">  <span class="comment">// address of the handle. The refCount of the object will also be incremented</span></div>
<div class="line">  <span class="keywordtype">void</span>  SetValue(<a class="code hl_typedef" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> x, <a class="code hl_typedef" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> y, <span class="keywordtype">void</span> *value);</div>
<div class="line">};</div>
<div class="ttc" id="aangelscript_8h_html_abfe11f5787462216b1682a5d3f5486be"><div class="ttname"><a href="angelscript_8h.html#abfe11f5787462216b1682a5d3f5486be">asALLOCFUNC_t</a></div><div class="ttdeci">void *(* asALLOCFUNC_t)(size_t)</div><div class="ttdoc">The function signature for the custom memory allocation function.</div><div class="ttdef"><b>Definition:</b> angelscript.h:645</div></div>
<div class="ttc" id="aangelscript_8h_html_ac8186f029686800b7ce36bde4a55c815"><div class="ttname"><a href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a></div><div class="ttdeci">unsigned int asUINT</div><div class="ttdoc">32 bit unsigned integer</div><div class="ttdef"><b>Definition:</b> angelscript.h:610</div></div>
<div class="ttc" id="aangelscript_8h_html_adeecc934971e695fc4441a47694860fb"><div class="ttname"><a href="angelscript_8h.html#adeecc934971e695fc4441a47694860fb">asFREEFUNC_t</a></div><div class="ttdeci">void(* asFREEFUNC_t)(void *)</div><div class="ttdoc">The function signature for the custom memory deallocation function.</div><div class="ttdef"><b>Definition:</b> angelscript.h:647</div></div>
<div class="ttc" id="aclassas_i_type_info_html"><div class="ttname"><a href="classas_i_type_info.html">asITypeInfo</a></div><div class="ttdoc">The interface for describing types This interface is used to describe the types in the script engine.</div><div class="ttdef"><b>Definition:</b> angelscript.h:3704</div></div>
</div><!-- fragment --><h1><a class="anchor" id="doc_addon_grid_2"></a>
Public script interface</h1>
<pre>
  class grid&lt;T&gt;
  {
    grid();
    grid(uint width, uint height);
    grid(uint width, uint height, const T &amp;in fillValue);

    uint width() const;
    uint height() const;
    void resize(uint w, uint h);

    T &amp;opIndex(uint x, uint y);
    const T &amp;opIndex(uint x, uint y) const;
  }
</pre><p><b>grid()</b><br  />
 <b>grid(uint width, uint height)</b><br  />
 <b>grid(uint width, height, const T &amp;in fillValue)</b><br  />
</p>
<p>The constructors initializes the grid object. The default constructor will create an zero sized grid.</p>
<p><b>uint width() const</b><br  />
 <b>uint height() const</b><br  />
</p>
<p>Returns the width and height of the grid.</p>
<p><b>void resize(uint w, uint h)</b></p>
<p>Resizes the grid to the new dimension. The elements that still fit in the grid will keep their values.</p>
<p><b>T &amp;opIndex(uint x, uint y)</b><br  />
 <b>const T &amp;opIndex(uint x, uint y) const</b><br  />
</p>
<p>The index operator returns a reference to one of the elements. If the index is out of bounds a script exception will be raised.</p>
<h1><a class="anchor" id="doc_addon_grid_3"></a>
Example usage in script</h1>
<pre>
  // Initialize a 5x5 map
  grid&lt;int&gt; map = {{1,0,1,1,1},
                   {0,0,1,0,0},
                   {0,1,1,0,1},
                   {0,1,1,0,1},
                   {0,0,0,0,1}};

  // A function to verify if the next area is walkable
  bool canWalk(uint x, uint y)
  {
    // If the map in the destination is 
    // clear, it is possible to wark there
    return map[x,y] == 0;
  }
</pre> </div></div><!-- contents -->
</div><!-- PageDoc -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated on Sun May 21 2023 10:12:39 for AngelScript by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.6 </li>
  </ul>
</div>
</body>
</html>
